import cv2
import numpy as np
import matplotlib.pyplot as plt

img = cv2.imread("../images/flower.png")
print(img.shape)
B,G,R = cv2.split(img)
cv2.imshow("red channel", R)
cv2.waitKey(0)
red_channel_img  = np.zeros_like(img,dtype="u1")
red_channel_img[:,:,2] = R
cv2.imshow("red channel image", red_channel_img)
cv2.waitKey(0)

#合并
merge_img = cv2.merge((R, G, B))
cv2.imshow("merge image", merge_img)
cv2.waitKey(0)
plt.imshow(merge_img)
plt.show()
B_zero = np.zeros_like(B, dtype="u1")
merge_img = cv2.merge((B_zero, G, R))
cv2.imshow("red green merge image", merge_img)
cv2.waitKey(0)